/*
 * @Author: byron
 * @Date: 2021-09-21 16:56:56
 * @LastEditTime: 2021-09-21 19:29:48
 */

import { INCREMENT, DECREMENT } from "./constant";

// 普通函数写法
// export function createIncrementAction(data) {
//     return {type:'increment',data}
// }
// export function createDecrementAction(data) {
//     return {type:'decrement',data}
// }

//箭头函数写法
export const createIncrementAction = (data) => ({ type: INCREMENT, data });
export const createDecrementAction = (data) => ({ type: DECREMENT, data });

// 异步action，就是指action的值为函数，异步action中一般会调用同步action，不是必须要用的
export const createIncrementAsyncAction = (data, time) => {
  console.log("asdasd");
  return () => {
    console.log("sada");

    setTimeout((dispatch) => {
      dispatch(createIncrementAction(data));
    }, time);
  };
};
